package com.lapelittle.framework.mapper;

import com.lapelittle.framework.entity.SysUser;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Param;
import java.util.List;

@Mapper
public interface SysUserMapper {
    @Select("SELECT * FROM sys_user")
    List<SysUser> findAll();
    
    @Select("SELECT * FROM sys_user WHERE username = #{username} AND status = 1")
    SysUser findByUsername(String username);
    
    @Select("SELECT * FROM sys_user WHERE mobile = #{mobile} AND status = 1")
    SysUser findByMobile(String mobile);
    
    @Select("SELECT * FROM sys_user WHERE email = #{email} AND status = 1")
    SysUser findByEmail(String email);
    
    @Insert("INSERT INTO sys_user(username, password, status) VALUES(#{username}, #{password}, 1)")
    int register(SysUser user);
    
    @Select("SELECT * FROM sys_user WHERE mobile = #{mobile} AND id != #{userId}")
    SysUser findByMobileExcludeSelf(@Param("mobile") String mobile, @Param("userId") Long userId);
    
    @Select("SELECT * FROM sys_user WHERE email = #{email} AND id != #{userId}")
    SysUser findByEmailExcludeSelf(@Param("email") String email, @Param("userId") Long userId);
    
    @Update("UPDATE sys_user SET nickname = #{nickname}, mobile = #{mobile}, " +
            "email = #{email}, avatar = #{avatar} WHERE id = #{id}")
    int updateUser(SysUser user);
    
    @Select("SELECT * FROM sys_user WHERE id = #{id}")
    SysUser findById(Long id);
} 